/**
 * Created by mapbar_front on 2019/8/10.
 */
import React,{Component} from 'react';

function MyInput(props){
    console.log('props',props.inputRef);
    return (
        <div>
            <input ref={props.inputRef}/>
        </div>
    )
}
class RefsDom2 extends Component{
    constructor(props){
       super(props);
       this.textInput = null;
       this.setTextInputRef = element=>{
           console.log('element',element);
           this.textInput = element;
       }
       this.handleClick=()=>{
           this.textInput && this.textInput.focus();
       }
    }
    componentDidMount(){
        //this.handleClick();
        //console.log('this.inputElement',this.inputElement);
        this.inputElement.focus();
    }
    render(){
        return(
            <div>
                {/*<input type="text" ref={this.setTextInputRef}/>*/}
                {/*<input type="text" onClick={this.handleClick}/>*/}
                <MyInput inputRef={el=>this.inputElement=el}/>
            </div>
        )
    }
}
export default RefsDom2;
